﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/AdminSite.Master" Inherits="System.Web.Mvc.ViewPage<ThanhCongJSC.Models.Content>" %>
<%@ Import Namespace="ThanhCongJSC.Helper"%>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Them moi - Cap nhat tin tuc
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="CssJsRef" runat="server">
    <link rel="stylesheet" type="text/css" href="<%= Application["Root"]%>/Content/css/jquery-ui-1.8.16.custom.css" /> 
    
    <script type='text/javascript' language='javascript' src='<%= Url.Content("~/ckeditor/ckeditor.js") %>'></script>
    <script type='text/javascript' language='javascript' src='<%= Url.Content("~/Scripts/jquery-ui-1.8.16.custom.min.js") %>'></script>
    
    <script type="text/javascript">
        jQ(function() {
            jQ("#tabs").tabs({ fx: [{ opacity: 'toggle', duration: 'normal' },   // hide option
                        {opacity: 'toggle', duration: 'fast'}]
            });
        });

        function Cancel() {
            window.location = '/Admin/NewsManagement/' + '<%= ViewData["ContentType"] %>';
        }

        function Validate() {
            // validate name
            var errorTitle = false;
            var errorTitleMsg = "";
            var title = jQ("#ContentTitle").val();
            if (title == '') {
                errorTitleMsg = "Tiêu đề tin tức không được bỏ trống!";
                errorTitle = true;
            }

            // validate detail
            var errorContent = false;
            var errorContentMsg = "";
//            var content = jQ("#ContentDetail").val();
//            if (content == '') {
//                errorContentMsg = "Nội dung tiếng Việt không được bỏ trống";
//                errorContent = true;
//            }

            if (errorTitle == true || errorContent == true) {
                jQ("#error-title").html(errorTitleMsg);
                jQ("#error-content").html(errorContentMsg);
                return false;
            }
            else {
                jQ("#error-title").html('');
                jQ("#error-content").html('');
                return true;
            }
        }

        function Submit() {
            if (Validate())
                document.forms[0].submit();
        }
	</script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>Thêm mới - Cập nhật tin tức</h2>
    
    <% Html.EnableClientValidation(); %> 
    <% using (Html.BeginForm("AddEditNews", "Admin", FormMethod.Post, new { id = "form-news", enctype = "multipart/form-data" }))
       {%>
        <div id="content-detail">
            <div id="tabs">
	            <ul>
		            <li><a href="#content-vn">Nội dung tiếng Việt</a></li>
		            <li><a href="#content-en">Nội dung tiếng Anh</a></li>
	            </ul>
    	        
	            <div id="content-vn">
	                <label><b>Hình đại diện</b></label>
	                <br />
	                <table>
	                    <tr>
	                        <td><img src="<%= Url.Content(Constant.PathImageTinTuc + Model.ContentImage ?? string.Empty) %>" alt="" width="150px" height="100px"/></td>
	                        <td><input id="file" type="file" name="file" /></td>
	                    </tr>
	                </table> 
                    
	                <p>
	                    <label><b>Tiêu đề</b></label>
	                    <br />
	                    <%= Html.TextBoxFor(b => b.ContentTitle, new { size = "100", maxlength = "50" })%>
	                    <span id="error-title" style="color:#FF0000"></span>
	                </p>
	                
	                <p>
	                    <label><b>Tóm tắt</b></label>
	                    <br />
	                    <%= Html.TextAreaFor(b => b.BriefDescription, new { rows = "5", cols = "99" })%>
	                </p>
	                
	                <p>
	                    <label><b>Nội dung</b></label>
	                    <br />
	                    <%= Html.TextAreaFor(b => b.ContentDetail) %>
	                    <span id="error-content" style="color:#FF0000"></span>
	                    <script type="text/javascript">
	                        CKEDITOR.replace('ContentDetail',
                            {
                                width: 800,
                                height: 500,
                                toolbarCanCollapse: false,
                                removePlugins: 'elementspath',
                                uiColor: '#DCDCDC',
                                filebrowserImageBrowseUrl: '/ckeditor/ImageBrowser.aspx?ImageFolderRoot=~/Content/images_tintuc/'
                            });
	                    </script>
	                </p> 
	            </div>
    	        
    	        <!-- noi dung tieng anh -->
	            <div id="content-en">
	                <p>
	                    <label><b>Tiêu đề</b></label>
	                    <br />
	                    <%= Html.TextBoxFor(b => b.ContentTitle2, new { size = "100", maxlength = "50" })%>
	                </p>
	                
	                <p>
	                    <label><b>Tóm tắt</b></label>
	                    <br />
	                    <%= Html.TextAreaFor(b => b.BriefDescription2, new { rows = "5", cols = "99" })%>
	                </p>
	                
	                <p>
	                    <label><b>Nội dung</b></label>
	                    <br />
	                    <%= Html.TextAreaFor(b => b.ContentDetail2) %>
	                    <script type="text/javascript">
	                        CKEDITOR.replace('ContentDetail2',
                            {
                                width: 800,
                                height: 500,
                                toolbarCanCollapse: false,
                                removePlugins: 'elementspath',
                                uiColor: '#DCDCDC',
                                filebrowserImageBrowseUrl: '/ckeditor/ImageBrowser.aspx?ImageFolderRoot=~/Content/images_tintuc/'
                            });
	                    </script>
	                </p>	            
	            </div>
            </div>
        </div>
        
        <br />
        <input type="button" class="button" value="Lưu lại" onclick="Submit()" /> &nbsp;&nbsp;&nbsp;
        <input type="button" class="button" value="Hủy bỏ" onclick="Cancel()" />
        
        <%= Html.HiddenFor(b=>b.ContentID) %>
        <input type="hidden" name="content-type" id="content-type" value="<%= ViewData["ContentType"] %>" />
    <%} %>
</asp:Content>
